package com.ruoyi.peoplegroup.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.peoplegroup.service.IPartnercategoryService;
import com.ruoyi.peoplegroup.service.impl.PartnerinfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.peoplegroup.domain.Partnerinfo;
import com.ruoyi.peoplegroup.service.IPartnerinfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合作单位信息Controller
 * 
 * @author gw
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/partnerinfo")
public class PartnerinfoController extends BaseController
{
    @Autowired
    private IPartnerinfoService partnerinfoService;
    @Autowired
    private IPartnercategoryService partnercategoryService;

    /**
     * 查询合作单位信息列表
     */
    @RequiresPermissions("peoplegroup:partnerinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(Partnerinfo partnerinfo)
    {
        startPage();
        List<Partnerinfo> list = partnerinfoService.selectPartnerinfoList(partnerinfo);
        for (Partnerinfo partnerinfo1:list){
            partnerinfo1.setCategoryName(partnercategoryService.selectPartnercategoryByCategoryId(partnerinfo1.getCategoryId()).getCategoryName());
        }
        return getDataTable(list);
    }

    /**
     * 导出合作单位信息列表
     */
    @RequiresPermissions("peoplegroup:partnerinfo:export")
    @Log(title = "合作单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Partnerinfo partnerinfo)
    {
        List<Partnerinfo> list = partnerinfoService.selectPartnerinfoList(partnerinfo);
        ExcelUtil<Partnerinfo> util = new ExcelUtil<Partnerinfo>(Partnerinfo.class);
        util.exportExcel(response, list, "合作单位信息数据");
    }

    /**
     * 获取合作单位信息详细信息
     */
    @RequiresPermissions("peoplegroup:partnerinfo:query")
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") Long partnerId)
    {
        return success(partnerinfoService.selectPartnerinfoByPartnerId(partnerId));
    }



    @RequiresPermissions("peoplegroup:partnerinfo:query")
    @GetMapping(value = "/partnerinfo/{partnerId}")
    public R<Partnerinfo> getInfo1(@PathVariable("partnerId") Long partnerId)
    {
        Partnerinfo partnerinfo=partnerinfoService.selectPartnerinfoByPartnerId(partnerId);
        return R.ok(partnerinfo);
    }


    /**
     * 新增合作单位信息
     */
    @RequiresPermissions("peoplegroup:partnerinfo:add")
    @Log(title = "合作单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Partnerinfo partnerinfo)
    {
        return toAjax(partnerinfoService.insertPartnerinfo(partnerinfo));
    }

    /**
     * 修改合作单位信息
     */
    @RequiresPermissions("peoplegroup:partnerinfo:edit")
    @Log(title = "合作单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Partnerinfo partnerinfo)
    {
        return toAjax(partnerinfoService.updatePartnerinfo(partnerinfo));
    }

    /**
 * 删除合作单位信息
 */
@RequiresPermissions("peoplegroup:partnerinfo:remove")
@Log(title = "合作单位信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{partnerIds}")
public AjaxResult remove(@PathVariable Long[] partnerIds)
{

    return toAjax(partnerinfoService.deletePartnerinfoByPartnerIds(partnerIds));
}


    @GetMapping("/getAllPartnerinfo")
    public AjaxResult getAllPartnerinfo()
    {
        List<Partnerinfo> list = partnerinfoService.selectPartnerinfoList(null);
        return success(list);
    }
}
